/**
 * http://usejsdoc.org/
 */
/**
 * 
 */
var PlayBar = (function () {
    // 初始化
 
    function PlayBar() { // 属性
        this.timer = {};
        this.datas = [];
        this.current = 0;
 
        this.init();
    }
    //
    // 初始化
    PlayBar.prototype.init = function (options) {
        var that = this;
 
    }
 
    PlayBar.prototype.loaddata = function (options) {
        var that = this;       
        var left=0;
        var days = [0, 1, 2, 3, 4];        
        var p = Products[options.id];
        var steps=100/(days.length*p.times.length);
        days.forEach(function (k) {
            var nowdays = moment().add(k, 'days'); 
            var daypath = nowdays.format("YYYY/MM/DD/");
            
            p.times.forEach(function (pt) {
 
                var daypath = nowdays.format("YYYY/MM/DD/");
 
                var tmpurl = p.source + "/" + daypath + p.tmplet.replace("{HHmm}", pt);               
                if (pt === "00") {
                    that.datas.push({
                        "id":options.id,
                        "left": (steps*left) + "%",
                        "title": nowdays.format("M-D"),
                        "value": tmpurl,
                        "type": "day"
                    });
                } else {
                    that.datas.push({
                    	 "id":options.id,
                    	 "left": (steps*left) + "%",
                        "title": pt,
                        "value": tmpurl,
                        "type": "hour"
                    });
                }
                left++;
            })
        })
 
 
        //      for(var i=0;i<=days;i++){
        //          that.datas.push({"left":(i*days)+"%","title":"8-"+i,"value":i+"v","type":"day"});
        //          for(var j=0;j<daystep;j++){
        //              that.datas.push({"left":(i*days+(100/days/daystep*(j+1)))+"%","title":"8-"+i,"value":i+"v:"+j*3+"00","type":"hour"});
        //          }
        //       }
        //
 
        var html = "";
        $.each(that.datas, function (index, val) {
 
            if (val.type === "day") {
                html += "<li data='" + index + "' style='left:" + val.left + "'><a style='padding:0;color:#ff0000' href='javascript:void(0);'>" + val.title +
                    " <span class='point'></span></a></li>";
            }
        })
        $("#timelabel").html(html);
 
 
        $("#timelabel li").on("click", function (e) {
            //设定进度
            $("#timeactive").css("width", $(this).css("left"));
            that.current = $(this).attr("data");
            
            that.show(that.datas[that.current]);
        });
    }
    PlayBar.prototype.play = function (options) {
        var that = this;
 
        function playlist() {
            if (that.current >= that.datas.length) {
                that.current = 0;
            }
            var c = that.datas[that.current];
            
            $("#timeactive").css("width", c.left);
            that.current++;
            //
            that.show(c);
        };
        this.timer = setInterval(playlist, 1000);
    }
    //显示内容
    PlayBar.prototype.show = function (options) {
        console.info(options);
    }
    PlayBar.prototype.stop = function (options) {
        clearInterval(this.timer);
    }
    // 返回
    return PlayBar;
})();